package com.example.jbmsuppliers.sinopec.activity;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.widget.Button;

import com.example.jbmsuppliers.R;
import com.example.jbmsuppliers.sinopec.adapter.FragmentAdapter;
import com.example.jbmsuppliers.sinopec.fragment.ListFragment;
import com.example.jbmsuppliers.sinopec.net.NetDeceVersion;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by 家帮忙 on 2017/3/2.
 */

public class MyIssue extends ActivityUse {
    //    @InjectView(R.id.pull_refresh_list)
//    PullToRefreshListView pullRefreshList;

    private final int MYISSUE = 0001;
    @InjectView(R.id.goback_ps_all)
    Button gobackPsAll;
    @InjectView(R.id.tabs)
    TabLayout tabs;
    @InjectView(R.id.viewpagerfb)
    ViewPager viewpagerfb;

    private NetDeceVersion netDeceVersion;
    private int num = 5;

    @Override
    protected int setContentView1() {
        return R.layout.lz_issue;
    }

    @Override
    protected void initView() {
        ButterKnife.inject(this);
        setTitle();

    }


    public interface getDateType {
        void setType(int i);


    }

    public void setTitle() {//设置标题栏
        List<String> titles = new ArrayList<>();
        titles.add("已发布");
//        titles.add("待审核");
        titles.add("未通过");
        for (int i = 0; i < titles.size(); i++) {
            tabs.addTab(tabs.newTab().setText(titles.get(i)));
        }
        final List<Fragment> fragments = new ArrayList<>();
        for (int i = 0; i < titles.size(); i++) {
            fragments.add(new ListFragment());
        }
        FragmentAdapter mFragmentAdapteradapter = new FragmentAdapter(getSupportFragmentManager(), fragments, titles);
        //给ViewPager设置适配器
        viewpagerfb.setAdapter(mFragmentAdapteradapter);
        //将TabLayout和ViewPager关联起来。
        tabs.setupWithViewPager(viewpagerfb);
        //给TabLayout设置适配器
        tabs.setTabsFromPagerAdapter(mFragmentAdapteradapter);

        viewpagerfb.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                ((ListFragment)fragments.get(position)).setType(position);

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });


    }

    @OnClick(R.id.goback_ps_all)
    public void onClick() {
        finish();
    }


}
